#include <iostream>

template<class T>
void dump(T a[], int n)
{
	using namespace std;
	for (int i = 0; i < n; ++i)
		cout << a[i] << " ";
	cout << endl;
}

template<class T>
void swap(T& a, T& b)
{
	T c = a;
	a = b;
	b = c;
}

template<class T>
void QSort(T a[], int s, int e)
{
	if (s >= e)
		return;
	T k = a[s];
	int i = s, j = e;
	while (i != j)
	{
		while (i<j && k <= a[j])
			--j;
		swap(a[i], a[j]);
		while (i<j && a[i] <= k)
			++i;
		swap(a[i], a[j]);
	}
	QSort(a, s, i - 1);
	QSort(a, i + 1, e);
}

int a[10] = { 13,27,19,2,8,12,2,8,30,89 };

int main()
{
	int n = sizeof(a) / sizeof(int);
	QSort(a, 0, n - 1);
	dump(a, n);
}